const ProductModel = require("../../models/ProductModle")

const ProductService = {
  add: async ({ title, introduction, detail, userid, cover, editTime }) => {
    return ProductModel.create({
      title, introduction, detail, userid, cover, editTime
    })
  },
  getList: async ({ _id }) => {
    return _id ? ProductModel.find({ _id }) : ProductModel.find({})
  },
  delList: async ({ _id }) => {
    return ProductModel.deleteOne({ _id })
  },
  // publish: async ({ _id, isPublish, editTime }) => {
  //   return NewsModel.updateOne({
  //     _id
  //   }, {
  //     isPublish, editTime
  //   })
  // },
  updateList: async ({ title, introduction, detail, cover, editTime, _id }) => {
    if (cover) {
      return ProductModel.updateOne({ _id }, {
        title, introduction, detail, cover, editTime
      })
    } else {
      return ProductModel.updateOne({ _id }, {
        title, introduction, detail, editTime
      })
    }
  }
}
module.exports = ProductService